package com.miao.config;

import com.miao.ForScan.Car;
import com.miao.UserClass.*;

import com.miao.entity.Boy;
import com.miao.entity.Cat;
import com.miao.entity.Color;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.stereotype.Controller;


@Configuration
//@PropertySource("application.properties")
@ComponentScan(value="com.miao.ForScan", excludeFilters = {
        @Filter(type = FilterType.ANNOTATION, classes = {Controller.class}),
        @Filter(type = FilterType.CUSTOM, classes = {MyTypeFilter.class})
})
@Import( {Cat.class, Color.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class})
public class JavaConfig4 {

    @Conditional(MyCondition1.class)
    @Bean("boy1")
    Boy boy1(){
        return new Boy("ZhangSan", 10);
    }


    @Conditional(MyCondition2.class)
    @Bean("boy2")
    Boy boy2(){
        return new Boy("LiSi", 20);
    }


    /*
    *  以下 这两个是 spring boot 扩展的注解，
    *   @ConditionalOnProperty  某个配置信息存在时，生效
    *   @ConditionalOnBean    某个Bean存在时，生效
     */
//    @ConditionalOnProperty(name = "JavaConfig5.enable", havingValue = "true")
//    @Bean("boy3")
//    Boy boy3(){
//        return new Boy("WangWu", 30);
//    }
//
//    @ConditionalOnBean(Car.class)
//    @Bean("boy4")
//    Boy boy4(){
//        return new Boy("ZhaoLiu", 40);
//    }


}
